﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/////////////////////////////
//using System.Data;
//using System.Data.SqlClient;
using MySql.Data.MySqlClient;
//using System.Data.SQLite;
/////////////////////////////
namespace PrinteMaster
{
    class Log
    {
        //public static DateTime m_ThisTime;
        public static string m_ServerIP = "";
        public static string m_ServerProt = "";
        public static bool debug(string msg)
        {
            output(msg);
            // 此处进行服务器交互
            return true;
        }
        public static bool error(string msg)
        {
            output(msg);
            // 此处进行服务器交互
            return true;
        }
        public static bool warning(string msg)
        {
            output(msg);
            // 此处进行服务器交互
            return true;
        }

        public static void output(string msg)
        {
            #if DEBUG
                Console.Write("["+DateTime.Now.ToString() +"] -- "+msg);
            #endif
        }
                        //SqlConnection
        public static MySqlConnection m_dbConnection;

        class test : MySqlHelper
        {
            
        }

        public static void db()
        {
            //MySqlHelper mh = new MySqlHelper();
            //MySqlHelper.Conn();
            test t = new test();
            //dgv. MySqlHelper.GetDataSet
            //
        }
        /// <summary>
        /// 管理员记录日志,记录到数据库.
        /// </summary>
        /// <param name="type">操作类型</param>
        /// <param name="managerId">员工ID</param>
        /// <param name="managerName">员工真实姓名</param>
        /// <param name="managerUser">员工账号</param>
        public static void managerLog(string type,string managerId,string managerName,string managerUser)
        {
            try
            {
                List<string> key = new List<string>();
                key.Add("时间");
                key.Add("操作类型");
                key.Add("操作员ID");
                key.Add("操作员姓名");
                key.Add("操作员账号");
                List<string> val = new List<string>();
                //val.Add("1");    
                val.Add("'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "'");
                val.Add("'" + type              +"'");
                val.Add("'" + managerId         + "'");
                val.Add("'" + managerName       + "'");
                val.Add("'" + managerUser       + "'");
                MySqlHelper.Result r = MySqlHelper.insert("员工操作记录", key, val);
            }
            catch (Exception e)
            {
                error(e.Message);
            }
        }

        /// <summary>
        /// 总端专属，将日志信息打印到服务器窗口内.
        /// </summary>
        /// <param name="msg"></param>
        public static void outLog(string msg)
        {
            //清屏幕
            if (主窗口.LogText.Text.Length >= 10000)
            {
                主窗口.LogText.Text = "";
            }
            string str = string.Format(" \r\n [{0}] - {1}",
                System.DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")
                , msg);
            主窗口.LogText.Text = 主窗口.LogText.Text+str;

        }

    }
}
